<template>
  <div class="aside">
    <el-menu
      active-text-color="#263445"
      background-color="#304156"
      class="el-menu-vertical-demo"
      text-color="#fff"
      :collapse="useStore.AsideIsShow"
      router
      unique-opened
      :default-active="defUrl"
    >
      <el-menu-item index="/index">
        <i class="iconfont homepage"></i>
        <span> 首页 </span>
      </el-menu-item>
      <el-sub-menu :index="'/' + p.name" v-for="p in menus" :key="p.id">
        <template #title>
          <i class="iconfont" :class="p.icon"></i>
          <!-- <el-icon>
            <location />
          </el-icon> -->
          <span>{{ p.title }}</span>
        </template>
        <template v-for="sub in p.children" :key="sub.id">
          <el-menu-item
            :index="'/' + p.name + '/' + sub.name"
            v-if="sub.hidden === 0"
          >
            <i class="iconfont" :class="sub.icon"></i>
            {{ sub.title }}
          </el-menu-item>
        </template>
      </el-sub-menu>
    </el-menu>
  </div>
</template>

<script setup lang="ts">
import { usePinia } from "@/store/index";
import { ref, watch } from "vue";
import { useRoute } from "vue-router";
const useStore = usePinia();
const menus = useStore.routes;

const defUrl = ref("/index");
const route = useRoute();
watch(
  () => route.path,
  () => {
    defUrl.value = route.path;
  },
  {
    immediate: true,
  }
);
</script>

<style scoped lang="less">
.aside {
  .is-active {
    color: #409eff;
  }

  .el-menu-vertical-demo {
    border-right: 1px solid #304156;
    width: 250px;
  }

  :deep(.el-menu--collapse) {
    width: 64px;
  }
}
</style>
